﻿using CodeCity.AutomationMachine.DomainModels;
using NRules.Fluent.Dsl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CodeCity.AutomationMachine.Rules
{
    public class HumanBornRule : Rule
    {
        public override void Define()
        {
            IEnumerable<Human> humen = null;
            When()
                .Query(() => humen, query => query.Match<Human>(x => !x.IsBorn).Collect().Where(x=>x.Any()));

            Then()
                .Do(context => Born(humen));
        }

        private void Born(IEnumerable<Human> humen)
        {
            foreach (var human in humen)
            {
                human.IsBorn = true;
                human.Temperature = Human.InitilizeTemperature;
            }
        }
    }
}
